﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IOrderInfoService
    {
        IQueryable<OrderInfo> GetOrderInfos();
        OrderInfo GetOrderInfo(int id);
        void CreateOrderInfo(OrderInfo orderInfo);
        void DeleteOrderInfo(int id);
        void SaveOrderInfo();
    }
    
    public class OrderInfoService : IOrderInfoService
    {
        private readonly IOrderInfoRepository orderInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public OrderInfoService(IOrderInfoRepository orderInfoRepository, IUnitOfWork unitOfWork)
        {
            this.orderInfoRepository = orderInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IOrderInfoService Members

        public IQueryable<OrderInfo> GetOrderInfos()
        {
            var orderInfos = orderInfoRepository.GetAll();
            return orderInfos;
        }

        public OrderInfo GetOrderInfo(int id)
        {
            var orderInfo = orderInfoRepository.GetById(id);
            return orderInfo;
        }

        public void CreateOrderInfo(OrderInfo orderInfo)
        {
            orderInfoRepository.Add(orderInfo);
            SaveOrderInfo();
        }

        public void DeleteOrderInfo(int id)
        {
            var orderInfo = orderInfoRepository.GetById(id);
            orderInfoRepository.Delete(orderInfo);
            SaveOrderInfo();
        }

        public void SaveOrderInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}